<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ taglib uri="http://www.myce.net.cn/ce-tag" prefix="ce"%>
<html>
<head>
<title>${key.select}</title>
<link href="${ctx}/styles/listTable.css" rel="stylesheet"	type="text/css">
<link href="${ctx}/styles/aux_window.css" rel="stylesheet"	type="text/css">
<link href="${ctx}/styles/mainmenu2.css" rel="stylesheet"	type="text/css">
<link href="${ctx}/styles/show.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript"	src="${ctx}/scripts/public.js"></script>
<script language="JavaScript" type="text/javascript"	src="${ctx}/scripts/div/common.js"></script>
<script language="JavaScript" src="${ctx}/scripts/common/prototype.js"></script>
<script type="text/javascript">
	var ACTION_URL="${ctx}/charge_charStoChoAction.do?";;
	function buildingOnChange(){
		$('form1').action=ACTION_URL+"method=initHouseList";
		//$('form1').target="houselist";
		$('form1').submit();
	}

	//返回已选房间表格用","隔开的id列表串
	function getHouseIdByTable(){
		var houseIds="";
		var objs=$('selectHouseTable').rows;
		for(var i=0;i<objs.length;i++){
			if(objs[i].cells.length<1){
				return houseIds;
			}
			houseIds = houseIds+objs[i].cells[0].tid+",";
		}
		return houseIds;
	}

	//以下方法为待选房间列表所用
	function addTd(newTr,id,text,width){
		var newTd=newTr.insertCell();
		if(id){
			newTd.onclick = addTrSelect;
			newTd.className ="2td_listTable_record_off";
		}else{
			newTd.className ="listTable_normal_word";
		}
		newTd.width=width;
		newTd.innerText=text;
		newTd.tid=id;
	}
	function addTdFirst(newTr,id,text){
		var newTd=newTr.insertCell();
		newTd.align="center";
		//newTd.onclick =function df(){alert(this.tid);};
		newTd.className ="listTable_normal_word";
		newTd.width="6%";
		newTd.innerText=text;
		newTd.tid=id;
	}
	//将选择的房间添加到已经房间表格中，如果已经添加，将不再添加
	function addTrSelect(obj){
		if(this.tid){
			obj=this;
		}

		if(!obj.tid || $('buildingCellId').disabled ){
			return;
		}

		if(containsTable(obj.tid,obj.innerText)){
			return ;
		}
		var newTr=$('selectHouseTable').insertRow();
		addTdSelect(newTr,obj.tid,obj.innerText);
	}

	//将选择的房间添加到已经选房间列表
	function addTdSelect(newTr,id,text){
		var newTd=newTr.insertCell();
		newTd.className ="2td_listTable_record_off";
		newTd.width="100%";
		newTd.innerHTML=text+"<a href='javascript:void(0)'><img src='${ctx}/images/ico_delete.gif' alt='${key.delete}' border='0'></a>";
		newTd.getElementsByTagName("a")[0].onclick=function (){
			$('selectHouseTable').deleteRow(this.parentElement.parentElement.rowIndex);
		};
		newTd.tid=id;
	}
	//根据房间id来判断所选房间是否已经选择
	function containsTable(tid,houseNumber){
		var meterId= parent.$('meterId')==null ? null : parent.$F('meterId');
		parent.checkExistCharSto(tid,houseNumber);
		if(parent.checkExistCharStoChoResult){
			return parent.checkExistCharStoChoResult;
		}

		var objs=$('selectHouseTable').rows;
		for(var i=0;i<objs.length;i++){
			if(objs[i].cells.length<1){
				return false;
			}
			if(tid==objs[i].cells[0].tid){
				return true;
			}
		}
	}
	//将待选的房间全部增加到已经房间列表中
	function addAllTr(){
		var objs=document.frames.houselist.$('tableHouse').rows;
		for(var i=0;i<objs.length;i++){
			for(var j=0;j<objs[i].cells.length;j++){
				addTrSelect(objs[i].cells[j]);
			}
		}
	}
	//清空已经房间表格
	function clearSelectTable(){
		var rows=$('selectHouseTable').rows;
		for(var i=rows.length-1;i>=0;i--){
			$('selectHouseTable').deleteRow(i);
		}
	}

	function init(){
		$('buildingCellId').disabled=true;
		$('tdSelectAll').disabled=true;
	}
</script>

</head>

<body onload="init();">
<form action="" id="form1" method="post" target="houselist">
<table width="100%" border="0" align="center" cellpadding="0"
	cellspacing="0" class="outtable">

	<tr>
		<td valign="top">
		<div class="leftTree">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">

			<tr>
				<td height="24">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td>
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td height="24">&nbsp;&nbsp;${key.selectedList}：<span
																			id="selectSpanMessage"
																			style="display:none;margin-left:10px;"> <img
																			src="${ctx}/images/validate/ErrorWarn.gif" width="15"
																			height="15" style="cursor: hand" alt="${key.selectTip}"
																			onClick="alert('${key.selectTip}');" /> </span></td>
							</tr>
							<tr>
								<td>
								<table width="100%" height="100" border="0" cellpadding="0"
									cellspacing="1">
									<tr>
										<td align="left" valign="top" nowrap class="LeftdownBlock1"
											style="padding:3px;">
										<div style="OVERFLOW: auto; WIDTH: 100%;  HEIGHT: 100%">
										<table border="1" cellspacing="3" cellpadding="0"
											id="selectHouseTable" class="lastselect"
											style="border-collapse:collapse" bordercolor="BCBFD2">

										</table>
										</div>
										</td>
									</tr>
								</table>
								</td>
							</tr>
						</table>
						</td>
					</tr>

				</table>
				</td>
			</tr>
		</table>
		</div>
		&nbsp;
		<div class="leftTree">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">

			<tr>
				<td height="25">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">

					<tr>
						<td width="24%">&nbsp;&nbsp;${key.buildingCell}： <ce:unitedSelect
							dataList="${buildingCellList}" name="buildingCellId"
							optionLabel='selectText' optionValue="selectId"
							selectText='${key.pleaseSelect}' onChange="buildingOnChange()" /></td>
						<td width="26%">
						<table border="0" cellpadding="0" cellspacing="0" id="ico1">
							<tr>
								<td class="toolbarico" id="tdSelectAll" onclick="addAllTr()" disabled><a href="javascript:void(0)"><img
									src="${ctx}/images/ico_xf.gif" border="0" align="absbottom"
									 /> ${key.selectAll}</a></td>
							</tr>
						</table>
						</td>
							<td width="50%" />
					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td>
				<iframe
					id="houselist" name="houselist" height="130PX" frameborder="0"
					border="0"
					src="${ctx}/charge_charStoChoAction.do?method=initHouseList"
					width="100%"></iframe>
				</td>
			</tr>
		</table>
		</div>
		</td>
	</tr>
</table>
</form>
</body>
</html>
